home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue70 / alfresco / TstStrms.dpr < prev   
Encoding:
Text File  |  2001-05-08  |  2.5 KB  |  120 lines

  1. program TstStrms;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils,
  7.   Classes,
  8.   AAStrms;
  9.  
  10. var
  11.   FSIn  : TFileStream;
  12.   FSOut : TFileStream;
  13.   BFIn  : TaaReadBufferFilter;
  14.   BFOut : TaaWriteBufferFilter;
  15.   TFIn  : TaaReadTextFilter;
  16.   TFOut : TaaWriteTextFilter;
  17.   RFIn  : TaaRegexTextFilter;
  18.   Debug : TaaDebugFilter;
  19.   WFIn  : TaaWindowFilter;
  20.   S     : string;
  21.   B     : array [0..20] of byte; {21 byte buffer}
  22.   BytesRead : longint;
  23. begin
  24.   writeln('Testing buffered filters...');
  25.  
  26.   FSIn := nil;
  27.   FSOut := nil;
  28.   BFIn := nil;
  29.   BFOut := nil;
  30.   try
  31.     FSIn := TFileStream.Create('AAStrms.pas', fmOpenRead);
  32.     BFIn := TaaReadBufferFilter.Create(FSIn, -1);
  33.     FSOut := TFileStream.Create('test1.tst', fmCreate);
  34.     BFOut := TaaWriteBufferFilter.Create(FSOut);
  35.  
  36.     BytesRead := BFIn.Read(B, sizeof(B));
  37.     while (BytesRead <> 0) do begin
  38.       BFOut.Write(B, BytesRead);
  39.       BytesRead := BFIn.Read(B, sizeof(B));
  40.     end;
  41.  
  42.   finally
  43.     BFOut.Free;
  44.     FSOut.Free;
  45.     BFIn.Free;
  46.     FSIn.Free;
  47.   end;
  48.  
  49.   writeln('Testing text and debug filters...');
  50.  
  51.   FSIn := nil;
  52.   FSOut := nil;
  53.   TFIn := nil;
  54.   TFOut := nil;
  55.   Debug := nil;
  56.   try
  57.     FSIn := TFileStream.Create('AAStrms.pas', fmOpenRead);
  58.     Debug := TaaDebugFilter.Create(FSIn, 'test2.log');
  59.     TFIn := TaaReadTextFilter.Create(Debug, -1);
  60.     FSOut := TFileStream.Create('test2.tst', fmCreate);
  61.     TFOut := TaaWriteTextFilter.Create(FSOut);
  62.  
  63.     while not TFIn.AtEndOfStream do begin
  64.       S := TFIn.ReadLine;
  65.       TFOut.WriteLine(S);
  66.     end;
  67.  
  68.   finally
  69.     TFIn.Free;
  70.     Debug.Free;
  71.     FSIn.Free;
  72.     TFOut.Free;
  73.     FSOut.Free;
  74.   end;
  75.  
  76.  
  77.   writeln('Testing regex filters...');
  78.  
  79.   FSIn := nil;
  80.   RFIn := nil;
  81.   try
  82.     FSIn := TFileStream.Create('AAStrms.pas', fmOpenRead);
  83.     RFIn := TaaRegexTextFilter.Create(FSIn, -1,
  84.                '^(procedure|function)');
  85.  
  86.     while not RFIn.AtEndOfStream do begin
  87.       S := RFIn.ReadLine;
  88.       writeln(S);
  89.     end;
  90.  
  91.   finally
  92.     RFIn.Free;
  93.     FSIn.Free;
  94.   end;
  95.  
  96.   writeln('Testing window filter...');
  97.  
  98.   FSIn := nil;
  99.   TFIn := nil;
  100.   WFIn := nil;
  101.   try
  102.     FSIn := TFileStream.Create('AAStrms.pas', fmOpenRead);
  103.     WFIn := TaaWindowFilter.Create(FSIn, 20000);
  104.     TFIn := TaaReadTextFilter.Create(WFIn, -1);
  105.  
  106.     while not TFIn.AtEndOfStream do begin
  107.       S := TFIn.ReadLine;
  108.       writeln(S);
  109.     end;
  110.  
  111.   finally
  112.     TFIn.Free;
  113.     WFIn.Free;
  114.     FSIn.Free;
  115.   end;
  116.  
  117.   writeln('Done');
  118.   readln;
  119. end.
  120.